var express = require('express');
var router = express.Router();
var mongo = require("./db");
var mongodb = require("mongodb");
var ObjectId = mongodb.ObjectId;
/* GET users listing. */
router.get('/', function(req, res, next) {
  // res.send('respond with a resource');
  res.send("主接口")
});
//添加接口
router.post("/add",function(req,res){
  var obj={
    mingcheng:req.body.mingcheng,
    leibie:req.body.leibie,
    radio:req.body.radio,
    yuanjia:req.body.yuanjia,
    shuliang:req.body.shuliang,
   xianjia:req.body.xianjia
    // time: new Date().getTime()
  }
  mongo("add","msglist",obj,function(){
    res.send({code:0,success:"添加成功"})
  })
})
//查询接口
router.get("/list",function(req,res){
  mongo("find","msglist",{},function(data){
    if(data.length==0){
      res.send({code:700,err:"暂无数据",data:[]})
    }else{
      res.send({code:0,success:"获取列表成功",data:data})
    }
  })
})
//删除接口
router.post("/del",function(req,res){
  mongo("del","msglist",{_id: ObjectId(req.body.id)},function(){
    res.send({code:0,success:"删除成功"})
  })
})
module.exports = router;
